package com.maixun.lib_comment.recyclerview

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

/**
 * 作者：Lmoumou
 * 时间：2020/8/5 16:01
 *
 * 未完善
 * 需要学习ListAdapter和DiffUtil
 */
abstract class BaseAdapter<T>(
    protected val mContext: Context,
    protected val dataList: MutableList<T>
) :
    RecyclerViewAdapter, RecyclerView.Adapter<ViewHolderImpl>() {

    private val mInflater by lazy { LayoutInflater.from(mContext) }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderImpl {
        return ViewHolderImpl(
            mInflater.inflate(viewType, parent, false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolderImpl, position: Int) {
        bindData(holder, position)
    }

    override fun getItemViewType(position: Int): Int {
        return itemViewType(position)
    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}